package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.service.ThumbService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @auther wangchenghao
 * @date 2020/9/22
 **/
@Controller
@ResponseBody
@RequestMapping("thumb")
public class ThumbController {
    @Autowired
    ThumbService thumbService;

    @ApiOperation("新增帖子点赞")
    @RequestMapping(value = "/addPostThumb", method = {RequestMethod.POST})
    public BaseModel addPostThumb(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                  @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        thumbService.addThumb(user_id, source_id, "post", model);
        return model;
    }
    @ApiOperation("检查帖子点赞")
    @RequestMapping(value = "/checkPostThumb", method = {RequestMethod.GET})
    public BaseModel checkPostThumb(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                  @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        thumbService.addThumb(user_id, source_id, "post", model);
        return model;
    }
    @ApiOperation("取消帖子点赞")
    @RequestMapping(value = "/deletePostThumb", method = {RequestMethod.DELETE})
    public BaseModel deletePostThumb(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                     @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        thumbService.deleteThumb(user_id, source_id, "post", model);
        return model;
    }
}
